package utils.nfc
{
	import utils.nfc.xml.Record;
	import utils.nfc.xml.Value;

	public class RecordType
	{
		public static const RECORD_TYPE_CALL:String			= "tel";
		public static const RECORD_TYPE_URL:String			= "url";
		public static const RECORD_TYPE_MAPURL:String		= "mapurl";
		public static const RECORD_TYPE_EMAIL:String		= "email";
		public static const RECORD_TYPE_VCARD:String		= "vcard";	
		public static const RECORD_TYPE_EVENT:String		= "event";	
		
		
		public static function getRecord(valueObject:Object,recordType:String):Array
		{
			var valueArray:Array = new Array();
			for (var i:int = 0; i < getValueTypes(recordType).length; i++) 
			{
				var type:String = getValueTypes(recordType)[i];
				valueArray.push(new Value(type,valueObject[type]));
			}
			var recordArray:Array = new Array();
			recordArray.push(new Record(recordType,valueArray));
			return recordArray;
		}
		
		public static function getRecords(valueObjectArray:Array,recordTypeArray:Array):Array
		{
			var recordArray:Array = new Array();

			for (var j:int = 0; j < valueObjectArray.length; j++) 
			{
				var valueArray:Array = new Array();
				for (var i:int = 0; i < getValueTypes(recordTypeArray[j]).length; i++) 
				{
					var type:String = getValueTypes(recordTypeArray[j])[i];
					valueArray.push(new Value(type,valueObjectArray[j][type]));
				}
				recordArray.push(new Record(recordTypeArray[j],valueArray));
			}
			
			return recordArray;
		}
		
		
		private static function getValueTypes(recordType:String):Array
		{
			switch(recordType)
			{
				case RECORD_TYPE_URL:
				{
					return ["uri"];
				}
				case RECORD_TYPE_MAPURL:
				{
					return ["uri"];
				}
				case RECORD_TYPE_EVENT:
				{
					return ["uri"];
				}
				case RECORD_TYPE_CALL:
				{
					return ["number"];
				}
				case RECORD_TYPE_EMAIL:
				{
					return ["mail","subj","text"];
				}
				case RECORD_TYPE_VCARD:
				{
					return ["vcard"];
				}
				default:{
					return ["fail"];
				}
			}
		
		}
		
		
		
	}
}